﻿// Decompiled with JetBrains decompiler
// Type: Netick.NativeUtils
// Assembly: Netick, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: 6726ECA1-C773-4CF7-8952-E81B30D93B52
// Assembly location: D:\WorkSpaceDemo\UPM\NetickForUnity\Netick\Runtime\Netick.dll
// XML documentation location: D:\WorkSpaceDemo\UPM\NetickForUnity\Netick\Runtime\Netick.xml

#nullable disable
namespace Netick;

internal static class NativeUtils
{
  public static unsafe void ResizeBuffer(
    IAllocator allocator,
    int newLength,
    int elementSize,
    ref int bufferSize,
    ref int* ptr)
  {
    int* ptr1 = ptr;
    void* dest = allocator.Allocate((ulong) (newLength * elementSize), out int _, out long _, false);
    MemoryAllocation.Copy(dest, (void*) ptr, (long) (bufferSize * elementSize));
    bufferSize = newLength;
    ptr = (int*) dest;
    allocator.Deallocate((void*) ptr1);
  }

  public static unsafe void Allocate(
    IAllocator allocator,
    bool clear,
    int initialCapacity,
    int elementSize,
    ref int bufferSize,
    ref int* ptr)
  {
    void* voidPtr = allocator.Allocate((ulong) (initialCapacity * elementSize), out int _, out long _, clear);
    ptr = (int*) voidPtr;
    bufferSize = initialCapacity;
  }

  public static unsafe void Deallocate(IAllocator allocator, ref int* Ptr)
  {
    allocator.Deallocate((void*) Ptr);
    Ptr = (int*) null;
  }
}
